package chenji.gunapi.pluginmessage;

import com.google.common.base.Charsets;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

import chenji.gunapi.pluginmessage.GunAPIPackage.Side;

public abstract class OutGunAPIPackage {
	protected ByteArrayDataOutput stream;

	public OutGunAPIPackage() {
		stream = ByteStreams.newDataOutput();
		stream.writeInt(this.getType());

	}

	public abstract int getType();

	public abstract String getStringType();

	public final Side getSide() {
		return Side.OUT;
	}

	public byte[] getByte() {
		return this.stream.toByteArray();
	}

	public void writeString(String s) {
		byte[] b = s.getBytes(Charsets.UTF_8);
		int length = b.length;
		this.stream.writeInt(length);
		this.stream.write(b);
	}
}
